/*
* PasswordJPanel.java
*
* Created on 15. Juni 2008, 15:40
*/
package org.netbeans.modules.languages.pl_sql.editor;
import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
/**
*
* @author SUMsoft
*/
public class PasswordJPanel extends javax.swing.JPanel {
/** Creates new form PasswordJPanel */
public PasswordJPanel() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
UserNamejLabel = new javax.swing.JLabel();
UserNamejTextField = new javax.swing.JTextField();
PasswordjLabel = new javax.swing.JLabel();
jPasswordField = new javax.swing.JPasswordField();
UserNamejLabel.setText(org.openide.util.NbBundle.getMessage(PasswordJPanel.class, "PasswordJPanel.UserNamejLabel.text")); // NOI18N
UserNamejTextField.setEnabled(false);
PasswordjLabel.setText(org.openide.util.NbBundle.getMessage(PasswordJPanel.class, "PasswordJPanel.PasswordjLabel.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(UserNamejLabel)
.addComponent(PasswordjLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
.addComponent(UserNamejTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(UserNamejLabel)
.addComponent(UserNamejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(PasswordjLabel)
.addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel PasswordjLabel;
private javax.swing.JLabel UserNamejLabel;
private javax.swing.JTextField UserNamejTextField;
private javax.swing.JPasswordField jPasswordField;
// End of variables declaration//GEN-END:variables
private Dialog dlg;
boolean isOK = false;
public boolean getisOK() {
return isOK;
}
public String getPassword() {
return String.copyValueOf(jPasswordField.getPassword());
}
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (DialogDescriptor.CANCEL_OPTION.equals(e.getSource())) {
dlg.setVisible(false);
}
if (DialogDescriptor.OK_OPTION.equals(e.getSource())) {
if (getPassword().length() == 0) {
JOptionPane.showMessageDialog(null, Utils.getBundle().getString("LBL_PassReq"),
Utils.getBundle().getString("LBL_InputError"), JOptionPane.ERROR_MESSAGE);
isOK = false;
return;
}
isOK = true;
dlg.setVisible(false);
}
}
};
public void ShowDialog(String username) {
this.UserNamejTextField.setText(username);
DialogDescriptor d = new DialogDescriptor(this, Utils.getBundle().getString("LBL_ConnectionInformation"), true,
NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.OK_OPTION, listener);
dlg = DialogDisplayer.getDefault().createDialog(d);
dlg.pack();
dlg.setVisible(true);
}
}